home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interplay's Learn to Program Basic (Review Copy)
/
Learn to Program Basic Review Copy (Interplay)(June 23, 1998).ISO
/
pc
/
ltpbasic
/
projects
/
motox.bas
< prev
next >
Wrap
BASIC Source File
|
1998-02-21
|
3KB
|
176 lines
Rem Motocross
Rem by Richard Temps
Dim bus(5)
pos = 0
Cls
Background "MotoJump"
cycle = LoadSprite("mtrcycle")
ramp = LoadSprite("motoramp")
cycleIdleSnd = LoadSound("BIKESLOW")
cycleGoSnd = LoadSound("BIKEFAST")
crowdSnd = LoadSound("CROWDLP")
crashSnd = LoadSound("TUMBLE")
cheerSnd = LoadSound("CROWD")
Rem Now start the game
Rem Set up a background sound of
Rem crowd noise
crowdNoise = LoopSound(crowdSnd)
Rem Create a random number of busses
busses = Random(0,5)
Rem Set up the screen
for t = 1 to busses
bus(t) = LoadSprite("bus")
SetSprite bus(t) to 73+ 36*(t-1), 186
next t
Rem Place second ramp
rampx = 73 + 36*busses
SetSprite ramp to rampx,182
Rem Now get the speed from the user
Rem that we will use to jump with
speed = 0
While speed < 1 OR speed > 100
Position 0,14
input "Whats the speed (1-100)?",speed
Wend
speed = speed * 1.5
position 0,14
for z = 0 to 38
print " ";
next z
rem Convert speed to m/s
speed = ((speed / 100.0) * 20.0)+5.0
Rem Convert m/s to pixels/s
speed = speed * 6.083333333 / 2.0
Rem Set up the data for the motorcycle
Rem this assumes a 40 degree angle for the ramp
up = .76604443 * speed
across = .642787609 * speed
start = timer()/1000.0
frame = 0
running = 1
rampelapsed = 0
jump = 0
latch = 0
rampy = 0
Rem Run the motorcycle up the ramp
Rem and make the jump
Rem Switch cycle sound to fast
chEngine = PlaySound(cycleGoSnd)
while running <> 0
curtime = (timer() / 1000.0) - start
x = -30 + (curtime* across)
Rem before we get to the ramp...
if x < 9 then
y = 196
ramptime = curtime
else
rampelapsed = curtime - ramptime
if jump = 0 then
frame = 1
Rem on the ramp, but not airborne
y = 194 - (rampelapsed * speed * .45)
if y < 161 then
jump = 1
jumpstart = curtime
endif
else
Rem airborne - calculate the position with regard to the force
Rem UP (as determined by the speed) minus the gravity DOWN
if y > 197 or x > 300 then running = 0
if running <> -1 then
jumpelapsed = curtime - jumpstart
Rem Jump calculations
up = jumpelapsed * speed * .45
gravity = 12 * jumpelapsed * jumpelapsed
y = 161 - up + gravity
Rem Changing frame changes which spriteframe is shown
Rem for the motorcycle as it ascends, levels out and then
Rem descends
If up > gravity and frame = 1 then
frame = 0
Rem At this point, change sound of cycle
StopChannel chEngine
chEngine = LoopSound(cycleIdleSnd)
EndIf
If gravity > up and frame = 0 then
frame = 2
Rem At this point, change sound again
StopChannel chEngine
chEngine = PlaySound(cycleGoSnd)
EndIf
Rem check for collision or landing
wheelx = x + 23
wheely = y + 19
if wheelx < rampx then
if wheely > 185 then running = 0
else
if latch = 0 then
latch = 1
ramptime = curtime
endif
Rem crash or completion conditions
rampy = 161 + (curtime - ramptime) * speed * .45
if wheely > 179 and wheelx < rampx then running = 0
if y > rampy and wheelx < rampx+50 and wheelx > rampx and gravity>up then
running = -1
frame = 2
speed = 100 ' speed up to get out!
endif
endif
else
y = 161 + (curtime - ramptime) * speed * .45
if y > 196 then
frame = 0
y = 196
if x > 280 then
running = 0
endif
endif
endif
endif
endif
SetSprite cycle frame frame
SetSprite cycle to x,y
wend
Rem Hide cycle if we're at end
HideSprite cycle
Rem End game: User won or crashed
Position 10,14
StopChannel crowdNoise
if y = 196 then
Print "You won!"
PlaySound(cheerSnd)
else
StopChannel chEngine
Print "You crashed!"
PlaySound(crashSnd)
endif
Sleep 25
End